package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.entity.Reservation;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.vo.ReservationCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CustomerReservationController extends BaseController {

    @Autowired
    private CustomerReservationService customerReservationService;

    //1.查询取消预约数量
    @GetMapping("/customer/reservation/cancelled-count")
    public ResponseResult<Integer> cancelledCount() {
        Integer data = customerReservationService.cancelledCount();
        return success(data);
    }

    //2. 查询每个时间段剩余预约次数
    @GetMapping("/customer/reservation/countByTime")
    public ResponseResult<List<ReservationCountVo>> countByTime(@RequestParam(name = "time")Long time) {
        List<ReservationCountVo> data = customerReservationService.countByTime(time);
        return success(data);
    }

    //3.新增预约
    @PostMapping("/customer/reservation")
    public ResponseResult createReservation(@RequestBody Reservation reservation) {
         customerReservationService.createReservation(reservation);
         return success();
    }

    //4.分页查询预约
    @GetMapping("/customer/reservation/page")
    public ResponseResult<PageResponse<Reservation>> findByPage(
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "status",required = false) Integer status) {
        PageResponse<Reservation> pageResponse =customerReservationService.findByPage(pageNum, pageSize, status);
        return success(pageResponse);
    }

    //5.取消预约
    @PutMapping("/customer/reservation/{id}/cancel")
    public ResponseResult cancelReservation(@PathVariable(name = "id") Long id) {
        customerReservationService.updateReservation(id);
        return success();
    }


}
